<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <!-- join将数组中的元素转换为字符串,元素通过指定的分隔符分隔 -->
    <!-- 语法:array.join(这里放分隔符) -->
    <!-- w3c实例 -->
    <p id="demo">点击按钮将数组作为字符串输出</p>
    <button onclick="myFunction()">点击</button>
    <script>
        function myFunction() {
            var fruits = ["苹果", "梨子", "荔枝", "西红柿"];
            var x = document.getElementById("demo");
            x.innerHTML = fruits.join(",");
        }
    </script>

</body>

</html>